# -- coding: utf-8 --
import numpy as np

# http://www.dyhjw.com/dyhjw/etf.html
# http://quote.eastmoney.com/globalfuture/AUTD.html

# 计算下一日的均线价格

gold_price = [369.48,362.3,361.14,357.37,355.39,353.94,353.71,350.8,352.11,353,
              351.64,349.64,351.88,353.92,355.98,347.07,345.89,348.04,345.15,
              344.29,345.48,344.94,342.79,345.85,346.87,345.44,356.08,351.35,
              354.01,346.44,341.29]

sliver_price = [4469,4396,4387,4293,4279,4244,4239,4211,4260,4255,4257,4243,4256,
                4260,4268,4219,4217,4286,4261,4254,4246,4238,4213,4283,4283,4279,
                4444,4358,4442,4370,4289]

five_day_average = 0


#均线计算
def day_avg(gold_price=gold_price,time=5): #默认黄金，默认5日均线
    five_day_average = 0

    for days in range(time):
        five_day_average += gold_price[days]

    five_day_average = five_day_average/5
    return five_day_average


#计算下一日的价格和五日均线重叠的极致价格
def best_support(gold_price = gold_price, time=4): #默认5日均线
    five_day_average = 0
    for days in range(time):
        five_day_average += gold_price[days]
    x = five_day_average/time
    return x

#计算下一日的价格和五日均线重叠的极致价格以及加上了浮动均值后的结果
def best_support_range(gold_price = gold_price, time=4): #默认5日均线 
    five_day_average = 0
    for days in range(time):
        five_day_average += gold_price[days]
    x = five_day_average/time
    y = gold_price[0]+(x-gold_price[0])*0.27 if gold_price[0]>gold_price[1] else gold_price[0]-(x+gold_price[0])*0.27
    return y

print(best_support_range(sliver_price[0:5]),best_support_range(gold_price[0:5]))

#print(best_point())
#print(best_point(9))
#print(best_point(19))
'''
print(day_avg(sliver_price))
print(best_support(sliver_price))
print(test)
print(best_support(test))
'''

test = gold_price[4:9]
test = gold_price[3:8]
test = gold_price[2:7]
test = gold_price[1:6]
test = gold_price[0:5]

def test_range(day=0):
    test = gold_price[day+1:day+6]
    distance = gold_price[day] - best_support(test)
    return distance/gold_price[day+1]*100



result = []

for day in range(len(gold_price)-5):
    result.append(test_range(day))

result.sort()

#print(result,np.mean(result), np.median(result))

